package test01.demo08.demo0802;

import org.junit.Test;

import java.lang.reflect.Method;

public class MyAnnotation {

    @Test
    @StandardDoc(date="2020-8-15",author = "Jory")
    public void test(){
        System.out.println("test.....");
    }

    @Test
    public void processAnnotation() throws Exception{
        //获取MyAnnotation类的Class对象
        Class clazz = MyAnnotation.class;
        //通过反射获取MyAnnotation类中名为test的方法
        Method testMethod = clazz.getDeclaredMethod("test");
        //判断此方法中是否存在StandardDoc这个注解
        if (testMethod.isAnnotationPresent(StandardDoc.class)){
            //如果存在该注解，则通过反射获取该注解的实例
            StandardDoc annotation = testMethod.getDeclaredAnnotation(StandardDoc.class);
            //打印出该注解中的属性值
            System.out.println(annotation.author());
            System.out.println(annotation.date());
            System.out.println(annotation.version());
        }
    }
}
